package com.benio.ycfdisplayer.fresco.photoview;

import android.graphics.drawable.Drawable;

import com.facebook.drawee.drawable.ForwardingDrawable;
import com.facebook.drawee.interfaces.DraweeHierarchy;

/**
 * 包裹{@link DraweeHierarchy#getTopLevelDrawable()}
 * <p>Fresco与PhotoView的结合使用
 * Created by zhangzhibin on 2016/10/9.
 */
class WrapperDrawable extends ForwardingDrawable {
    private int mWidth = -1;
    private int mHeight = -1;

    public WrapperDrawable(Drawable drawable) {
        super(drawable);
    }

    @Override
    public int getIntrinsicWidth() {
        if (mWidth < 0) {
            mWidth = super.getIntrinsicWidth();
        }
        return mWidth;
    }

    @Override
    public int getIntrinsicHeight() {
        if (mHeight < 0) {
            mHeight = super.getIntrinsicHeight();
        }
        return mHeight;
    }

    /*
     * 改变Drawable的宽度，因为Fresco返回的{@link com.facebook.drawee.generic.RootDrawable}
     * 始终返回-1，而PhotoView需要使用该宽度才能正确显示
     */
    public void setIntrinsicWidth(int width) {
        mWidth = width;
    }

    public void setIntrinsicHeight(int height) {
        mHeight = height;
    }
}
